
import java.util.ArrayList;
import java.util.Collections;

import common.Base;
import room.Room;
import room.RoomMgr;
import tsql.sqlTest;
import user.User;
import user.UserMgr;

public class CTest {
    public static void main(String[] args) {
        System.out.println("---------------------- hellas 0000001 ----------------------------");

        // System.load(new String("ss"));

        // 语法测试
        if (true) {
            CBase cb = new CBase();
            cb.run();
            // 测试静态共享
            cb.msX += 11;
            CBase.msX++;

            CBase cb0 = cb;
            // 测试对象引用
            cb0.mX += 12;
            System.out.printf("cbase mX=%d, msX=%d\n", cb.mX, CBase.msX);

            cb.testJson();

            Integer i1 = 1;
            Integer i2 = i1;
            i2 += 11;

            // Base cm = new Base();
            // Base.mRobotId++;
            Base.addRobotID();
            // cm.addRobotID();
            System.out.printf("base robotId=%d\n", Base.getRobotID());

            System.out.println("---------- array sort");
            ArrayList<Integer> scores = new ArrayList<>();
            scores.add(11);
            scores.add(7);
            scores.add(15);
            scores.add(2);

            Collections.sort(scores,
                    (o1, o2) -> Integer.compare(o1, o2));// 升序 对调o1/o2即为降序
            for (Integer e : scores) {
                System.out.printf("%d,", e);
            }
            System.out.println();
        }

        // ========================================================================================
        System.out.println("---------------- 棋牌测试 begin ----------------");

        if (true) {
            Room rm = new Room(1, 2);
            rm.showStatus(); // 测试枚举
        }

        RoomMgr roomMgr = RoomMgr.getInstance(); // 房间管理器
        UserMgr userMgr = UserMgr.getInstance(); // 角色管理器

        roomMgr.createRoom(21); // 创建房间

        int gsock = 33; // sock模拟值
        User u = new User(userMgr, 1001, gsock, false); // 创建角色
        gsock++;

        // 进出房间
        System.out.println();
        roomMgr.onEnterRoom(u, 13);
        roomMgr.onEnterRoom(u, 11);

        Room rm = roomMgr.createRoom(11); // 再建一个
        roomMgr.onLeaveRoom(u);
        roomMgr.onEnterRoom(u, 14);

        // 押注
        System.out.println();
        int[] betRatios = Room.getArrBetRatio();
        for (int i = 0; i < betRatios.length; i++) {
            roomMgr.onBet(u, i, Room.randBetScore());
        }
        roomMgr.onBet(u, 0, 10); // ok
        roomMgr.onBet(u, 5, 44);
        roomMgr.onBet(u, 0, 10); // ok
        roomMgr.onBet(u, 8, 10);
        roomMgr.onBet(u, 3, 5000); // ok
        roomMgr.onBet(u, 11, 10);
        roomMgr.onBet(u, 4, 5000); // ok

        // 状态机测试
        boolean bOnTimer = true;
        if (bOnTimer) {
            System.out.println();
            for (int i = 0; i < 42; i++) {
                roomMgr.onTimer();
            }
        }

        // 离开房间
        System.out.println();
        roomMgr.onLeaveRoom(u);
        roomMgr.onLeaveRoom(u);

        System.out.println();
        u.testBet();
        roomMgr.onBet(u, 3, 1);

        System.out.println();
        rm.showBet();

        System.out.println("---------------- 棋牌测试 end ----------------");
        // ========================================================================================
        new sqlTest().done();

        // ========================================================================================

        System.out.println("----- c test end -------------------");
    }
}
